﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using VBDWebMobile;
using System.Web.Security;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    public WebService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    /// <summary>
    /// Dung Webservice de giu lai session as goi ajax
    /// </summary>
    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void Login()
    {
        string username = System.Web.HttpContext.Current.Request.Form.Get("Name");
        string password = System.Web.HttpContext.Current.Request.Form.Get("PW");
        string sReult = "{Result: false}";
        Users users = new Users();
        if (users.CheckUser(username, password))
        {

            //if (HttpContext.Current.Request.QueryString["ReturnUrl"] == null)
            //{
            //    FormsAuthentication.SetAuthCookie(username, false);
            //}
            //else
            //{
            //    FormsAuthentication.RedirectFromLoginPage(username, false);
            //}
            HttpContext.Current.Session["User"] = username;
            sReult = "{Result: true}";
         }
        HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.DeserializeObject(sReult));
    }
    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void Logout()
    {
        string sReult = "{Result: true}";
        HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.DeserializeObject(sReult));

    }
}
